﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using IB.Common.Base;

namespace UIListProducts
{
    public partial class ProductDetail : V_ListTypeBase
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            int prdid = ParentLoad.ProductID;
            var product = (from p in V_Base.Data.CV_Products
                           where p.ProductID == prdid
                           select p).FirstOrDefault();

            if (product != null)
            {
                txtTitle.InnerHtml = product.Title;
                txtDescript.InnerHtml = product.ShortContent;
                txt_content.InnerHtml = product.Content;
                txtTitleCt.InnerHtml = product.Title;
                txtPrice.InnerHtml = "Giá : "+((product.Price.Value==0)?ParentLoad.NoPrice:(product.Price.Value.ToString("##,###,###") + ",000 VND"));

                prImg.ImageUrl = ParentLoad.GetWebImgOf(LocationImage.Product, product.ImageName);
               

                var imgs = from im in V_Base.Data.CV_ImageProducts
                           where im.ProductID == prdid
                           select im;

                rptImgProduct.DataSource = imgs;
                rptImgProduct.DataBind();


                //lay cac san pham lien quan

                var pronewer = (from pr in V_Base.Data.CV_Products
                                join cat_ in V_Base.Data.CV_CatProducts on pr.CatID equals cat_.CatID
                                where pr.ProductID > prdid && (cat_.PortalID==ParentLoad.PortalId)
                                orderby pr.ProductID ascending
                                select pr).Take(10);

                var proolder = (from pr in V_Base.Data.CV_Products
                                join cat_ in V_Base.Data.CV_CatProducts on pr.CatID equals cat_.CatID
                                where pr.ProductID < prdid && (cat_.PortalID == ParentLoad.PortalId)
                                orderby pr.ProductID descending
                                select pr).Take(10);

                rptNewer.DataSource = pronewer;
                rptNewer.DataBind();

                rptOlder.DataSource = proolder;
                rptOlder.DataBind();
            }

        }
    }
}